﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GameOverController : MonoBehaviour {
     
    Vector3 canvasVector;
    Vector3 oldPosition;
    public static Vector3 oldPos;
    Text mainScore, overScore;
    UserHandler uhScript;
    Button saveScoreButton;
    void Start()
    {
        
        canvasVector = this.transform.parent.position;
        oldPosition = this.transform.position;

        mainScore = UIManager.Instance.GetUIByName(NameManager.PANEL_MAIN, NameManager.TXT_SCORE).GetComponent<Text>();
        overScore = UIManager.Instance.GetUIByName(NameManager.PANEL_OVER, NameManager.TXT_SCORE).GetComponent<Text>();
        uhScript = UIManager.Instance.GetUIByName(NameManager.PANEL_LOGIN, NameManager.PANEL_LOGIN_DIALOG).GetComponent<UserHandler>();
        
        //获取保存按钮，注册事件
        saveScoreButton = UIManager.Instance.GetUIByName(this.transform, NameManager.BTN_SAVESCORE).GetComponent<Button>();
        saveScoreButton.onClick.AddListener(OnClick_SaveScore);
        oldPos = oldPosition;
    }

    public void Display()
    {
        //gameObject.SetActive(true);
        //saveScoreButton.interactable = true;//启用交互功能
        overScore.text = mainScore.text;
        //gameObject.transform.position = canvasVector;
        /*iTween.MoveTo(gameObject, iTween.Hash(
            "position", canvasVector, "easetype", iTween.EaseType.easeInOutBounce));*/
    }
    
    public  void Hide()
    {
        //gameObject.SetActive(false);
        gameObject.transform.position = oldPosition;
        /*iTween.MoveTo(gameObject, iTween.Hash(
                "position", oldPosition, "easetype", iTween.EaseType.easeInOutBounce));*/
    }

    //重新开始
    public void Restart()
    {
        //Application.LoadLevel(Application.loadedLevel);
        Hide();
        GameObject.FindObjectOfType<GameController>().Restart();
    }

    public void OnClick_SaveScore()
    {
        uhScript.DisplayLogin(mainScore.text);
        saveScoreButton.interactable = false;//取消交互功能
    }
    public void ResBegin()
    {
        Hide();
        //GameObject.FindObjectOfType<GameController>().ReGegin();
        GameObject.FindObjectOfType<GameController>().GuainBtnClick();
    }
    
}
